#include "Ui/ModuleViewWrapper.h"
#include "Component/Util/AppModule.h"
#include "Component/Util/AppModuleView.h"
#include "Component/Util/AppModuleModel.h"

ModuleViewWrapper::ModuleViewWrapper(const shared_ptr<AppModule>& ptr) : 
			QMdiSubWindow()
{
	QWidget* view = ptr->getModuleView();
	m_Model = ptr->getModuleModel();
	setWidget(view);

	this->setAttribute(Qt::WA_DeleteOnClose);
	this->setWindowTitle(ptr->getModuleName());

	m_Model->restoreGeometry(this);
}

QSize ModuleViewWrapper::sizeHint() const {
	return widget()->size();
}	

void ModuleViewWrapper::showEvent(QShowEvent *showEvent)
{
	

	QMdiSubWindow::showEvent(showEvent);
}

void ModuleViewWrapper::closeEvent(QCloseEvent *closeEvent)
{
	m_Model->saveGeometry(this);
	QWidget* wid = widget();
	setWidget(NULL);

	if (wid) {
		wid->setParent(NULL);
	
		if (wid->testAttribute(Qt::WA_DeleteOnClose)) {
			delete wid;
		}
	}

	QMdiSubWindow::closeEvent(closeEvent);
}
